package com.lufei4.chestnut.orbyun.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.lufei4.chestnut.view.MyApp;

/**
 * @ProjectName: Chestnut
 * @Package: com.lufei4.chestnut.orbyun.db
 * @ClassName: MySQLiteHelper
 * @Description: java类作用描述
 * @Author: liushijiang 15833013864@163.com
 * @CreateDate: 2020/9/25 13:57
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/9/25 13:57
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

class MySQLiteHelper extends SQLiteOpenHelper {

    private static final String TAG = "MySQLiteHelper";
    //数据库建表语句
    public static final String sql = "create table SqliteDemo (id integer primary key autoincrement, name text(4),address text(5))";
    public static final String sql1 = "create table test1 (id integer primary key autoincrement, name text(4),address text(5))";

private static  MySQLiteHelper instance;
    public MySQLiteHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }


    public static synchronized MySQLiteHelper getInstance(Context context) {
        if (instance == null) {
            instance = new MySQLiteHelper(context, "Blcs", null, 1);
        }
        return instance;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "onCreate: " );
        db.execSQL(sql);
    }

    /**
     * 版本更新
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "onUpgrade: " );
        if (oldVersion==1){
            db.execSQL(sql1);
        }
    }
}
